<%@page import="com.kaishengit.entity.Prod"%>
<%@page import="com.kaishengit.entity.User"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>My JSP 'main.jsp' starting page</title>
    <script type="text/javascript" src="js/jquery.js"></script>
  </head>
  
  <body>
  	
  
    
    <a href="prod.jspx?_m=save">new product</a>
    <p></p>
    <table border="1" width="70%">
    	<tr>
    		<th>Index</th>
    		<th>ID</th>
    		<th>Name</th>
    		<th>Price</th>
    		<th>Action</th>
    	</tr>
    	<c:if test="${fn:length(pager.result)==0}">
    		<tr>
    			<td colspan="5">没有任何商品</td>
    		</tr>
    	</c:if>
		<c:forEach items="${requestScope.pager.result}" var="p" varStatus="v">
    	<tr>
    		<td>${v.count}</td>
    		<td>${p.id}</td>
    		<td>${p.prodName}</td>
    		<td>￥${p.price}</td>
    		<td>
    			<a href="prod.jspx?_m=get&id=${p.id}">edit</a>
    			<a class="del_link" rel="${p.id}" href="javascript:;">delete</a>
    		</td>
    	</tr>
    	</c:forEach>
    </table>
    <c:choose>
    	<c:when test="${pager.nowPage != 1}">
    		<a href="prod.jspx?p=${pager.nowPage - 1}">上一页</a>
    	</c:when>
    	<c:otherwise>
    		上一页
    	</c:otherwise>
    </c:choose>
    <c:choose>
    	<c:when test="${pager.nowPage != pager.totalPage }">
    		<a href="prod.jspx?p=${pager.nowPage + 1}">下一页</a>
    	</c:when>
    	<c:otherwise>
    		下一页
    	</c:otherwise>
    </c:choose>
    
    <script type="text/javascript">
    	$(document).ready(function(){
    		$(".del_link").click(function(){
    			var id = $(this).attr("rel");
    			if(confirm("确定要删除此数据？")) {
					window.location.href = "prod.jspx?_m=del&id=" + id;
    			}
    			
    		});
    		
    	});
    	
    </script>
    
    
  </body>
</html>
